{template 'common/header-gw'}
	<ol class="breadcrumb">
		<li><a href="./?refresh"><i class="fa fa-home"></i></a></li>
		<li><a href="{url 'system/welcome'}">系统</a></li>
		<li class="active">公众号列表</li>
	</ol>
	<div class="clearfix" style="margin-bottom:5em;">
		<form action="">
			<input type="hidden" name="c" value="account">
			<input type="hidden" name="a" value="batch">
			<div class="form-group">
				<div class="input-group">
					<input type="text" class="form-control" placeholder="请输入微信公众号名称" name="keyword" value="{$_GPC['keyword']}">
					<div class="input-group-btn">
						<button class="btn btn-default"><i class="icon-search"></i> 搜索</button>
					</div>
				</div>
			</div>
		</form>
		<div class="input-group">
			<a class="btn btn-primary" href="{url 'account/post-step'}"><i class="fa fa-plus"></i> 添加公众号</a>
		</div>
		<br>
		<div class="panel panel-default">
			<div class="panel-body" style="overflow:auto;">
				<form action="" method="post" id="form-delete" class="table-responsive">
					<input type="hidden" name="c" value="account">
					<input type="hidden" name="a" value="batch">
					<input type="hidden" name="do" value="delete">
					<table class="table">
						<thead>
						<tr>
							<th style="width:60px;">选择</th>
							<th style="width:220px;">主公众号名称</th>
							<th style="width:150px;">服务套餐</th>
							<th style="width:170px;">是否设置服务到期时间</th>
							<th style="width:200px;">到期时间</th>
							<th style="width:120px;">到期前服务套餐</th>
							<th style="width:350px;">操作用户</th>
						</tr>
						<thead>
						{loop $list $uni}
						<tr>
							<td><input type="checkbox" name="accoundid[]" value="{$uni['uniacid']}"></td>
							<td>{$uni['name']}</td>
							<td>{$uni['group']['name']}</td>
							<td>
								{if $uni['groupdata']['isexpire'] == 1}
								<span class="label label-success">是</span>
								{else}
								<span class="label label-danger">否</span>
								{/if}
							</td>
							<td>
								{if $uni['groupdata']['isexpire'] == 1}
								{php echo date('Y-m-d H:i', $uni['groupdata']['endtime'])} {if $uni['groupdata']['endtime'] <= TIMESTAMP}<br/><span class="label label-warning">已到期</span><br> 仅能使用'基础服务'套餐功能{/if}
								{else}
								<span class="label label-danger">不限制</span>
								{/if}
							</td>
							<td>
								{if $uni['groupdata']['isexpire'] == 1}
								{$groups[$uni['groupdata']['oldgroupid']]['name']}
								{else}

								{/if}
							</td>
							<td style="white-space:normal; line-height:25px;">
								{loop $uni['userdata'] $user}
								{if $user['role'] == 'manager'}
								<span class="label label-success" title="管理员">{$user['username']}</span>
								{else}
								<span class="label label-danger" title="操作员">{$user['username']}</span>
								{/if}
								{/loop}
							</td>
						</tr>
						{/loop}
						<tr>
							<td><input type="checkbox" id="checkall" onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});"></td>
							<td colspan="6">
								<input id="delete" class="btn btn-primary" value="删除" type="button"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<input id="group" class="btn btn-primary" value="更改套餐" type="button"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								{if $_W['isfounder']}
								<input id="operator" class="btn btn-primary" value="添加账号操作员" type="button">
								{/if}
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	{$pager}
	</div>
	<div id="footer-group" class="hide">
			<span name="submit" id="submit" class="pull-right btn btn-primary" onclick="$('#form-group').submit();">保存</span>
	</div>
	
	
<script>
	require(['bootstrap', 'util', 'biz'],function($, u, biz){
		$('.account .panel-heading a, .btn').hover(function(){
			$(this).tooltip('show');
		},function(){
			$(this).tooltip('hide');
		});
		
		$('#delete').click(function(){
			var arr = '';
			var mode = '';
			$("[name='accoundid[]']:checked").each(function(){
				arr += mode + $(this).val();
				mode = ',';
			});
			if(arr == '') {
				u.message('您没有选择要操作的公众号');
				return;
			}
			if(confirm('您确定要删除吗')) {
				$('#form-delete').submit();
			}
		});
		
		$('#group').click(function(){
			var arr = '';
			var mode = '';
			$("[name='accoundid[]']:checked").each(function(){
				arr += mode + $(this).val();
				mode = ',';
			});
			if(arr == '') {
				u.message('您没有选择要操作的公众号');
				return;
			}
			$.get("{php echo url('account/batch/modal')}" + '&arr=' + arr , function(data){
				var obj = u.dialog('公众号套餐更改', data, $('#footer-group').html());
				obj.modal('show');
			});
		});
		
		$('#operator').click(function(){
			var arr = '';
			var mode = '';
			$("[name='accoundid[]']:checked").each(function(){
				arr += mode + $(this).val();
				mode = ',';
			});
			if(arr == '') {
				u.message('您没有选择要操作的公众号');
				return;
			}
			var seletedUserIds = {php echo json_encode(array(1));};
			biz.user.browser(seletedUserIds, function(us){
				$.post('{php echo url('account/batch');}', {'uniacidstr': arr, 'do': 'operator', uid: us}, function(dat){
					if(dat == 'success') {
						u.message('添加账号操作员成功', "{php echo url('account/batch')}", 'success')
					} else {
						u.message('操作失败, 请稍后重试, 服务器返回信息为: ' + dat);
					}
				});
			},{mode:'invisible'});

		});
	});
	

	
</script>
{template 'common/footer-gw'}